// pages/repair/repair.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    repairList:[],
    ownerName:'',
    repairStatus:''
  },
  toRepairList(){
    wx.navigateTo({
      url: '/pages/repairlist/repairlist',
    })
  },
  toDetail(e){
    console.log(e.currentTarget.dataset.id);
    let RepairId=wx.setStorageSync('RepairId',e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '../detail/detail',
    })
    
  },
  bindSearchConfirm(e){
    let that=this;
    console.log(e.detail.value);
    console.log(this.data.ownerName);
    wx.request({
      url: 'http://localhost/repair/selectDeviceName',
      data:{
        ownerName:this.data.ownerName,
        deviceName:e.detail.value
      },
      success:function(result){
        console.log(result.data);
        that.setData({
          repairList:result.data
        })
      }
    })
  },
  delete(e){
    console.log(e.currentTarget.dataset.id);
    wx.request({
      url: 'http://localhost/repair/deleteRepairId',
      data:{
        repairId:e.currentTarget.dataset.id
      },
      success(result){
        wx.reLaunch({
          url: '../repair/repair',
        })
        if(result.data.code==0){  
          wx.showToast({
            title: result.data.msg,         
          })
    
        }else{
          wx.showToast({
            title: result.data.msg,
          })
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that=this;
    // 页面初始化 options为页面跳转所带来的参数
    let userInfo=wx.getStorageSync('userInfo');

    let repairStatus=wx.getStorageSync('repairStatus');
   
    if(userInfo){
      userInfo =JSON.parse(userInfo);
      this.setData({
        ownerName:userInfo.ownerName,
        communityName:userInfo.communityName
      })
      console.log(this.data.ownerName);
    }
    if(repairStatus){
      this.setData({
        repairStatus:repairStatus
      })
    }
    console.log(this.data.repairStatus);

    wx.request({   
      url: 'http://localhost/repair/getRepair',
      data:{
        ownerName:this.data.ownerName,
        status:this.data.repairStatus
      },
      success:function(result){
        console.log(result.data);
        that.setData({
          repairList:result.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})